<?php

declare(strict_types=1);

namespace App\Helpers;

use Hyperf\Utils\Context;

/**
 * OpenInstall的数据接口库
 */
class OpeninstallUtil
{
    const API_HOST = 'https://data.openinstall.io/';

    //openInstall apiKey
    const API_KEY = [
        'com.xylx.wchat' => '3de1984abe9336cc2ed015aea4cfb44e4dfa8c433408bee4927d38ac',//陌玩
        'com.chat.myu'   => 'f0fc25c5210624493be9dfdd6f4da5ac29369c8dc01ccedcc5f8458a',//陌遇
        'com.mengyao.life' => 'a610d52e2746f49e250ac652ee7fd44f19812b951ae3ec9f343972b0',//萌瑶
        'com.pengchen.penglive' => '32c3e9057f0624df63c5677ee26d5d0cc1ce97e52ff6228c3881758d',//乐娱交友
    ];

    /**
     * 新增安装数
     */
    static function getGrowth($start = '', $end = '', $channel = '', $packName = '', $exludeDup = false)
    {
        if (!isset(self::API_KEY[$packName])) return [];
        $url = self::API_HOST . 'data/event/growth';
        $queryParams = [
            'apiKey' => self::API_KEY[$packName],
            'channelCode' => $channel,
            'platform' => 'android',
            'beginDate' => $start,
            'endDate' => $end,
            'groupBy' => 'day',
            'excludeDuplication' => $exludeDup ? '1' : '0'
        ];
        $ret = Helper::httpReq($url, $queryParams, 'urlencoded', 'GET');
        return $ret ? json_decode($ret, true) : [];
    }
}
